from django.shortcuts import render
from rest_framework.filters import OrderingFilter
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.permissions import AllowAny
from rest_framework.views import APIView

from curriculum.models import Follow
from routes.models import PathModel, Phases
from rest_framework import viewsets
from routes.serializers import PathModelSerializer, PhasesModelSerializer


# Create your views here.

class PathView(viewsets.ModelViewSet):
    # 自定义权限类
    permission_classes = (AllowAny,)
    queryset = PathModel.objects.all()
    serializer_class = PathModelSerializer


class PhasesView(viewsets.ModelViewSet):
    # 自定义权限类
    permission_classes = (AllowAny,)
    queryset = Phases.objects.all()
    serializer_class = PhasesModelSerializer

    # 指定过滤方法类, 排序方法类, 一个或多个
    filter_backends = (DjangoFilterBackend,OrderingFilter)  # 同时支持过滤和排序

    # 指定排序字段, 不设置, 排序功能不起效
    ordering_fields = ('create_time', 'update_time', 'follows')

    # 指定过滤字段, 不设置, 过滤功能不起效
    filter_fields = ('ppath', 'numb')






































